Attribute VB_Name = "CodeMod"
' /* Declare The Function To Set The Window On Top */
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

' /* Declare The Constants That Work With Setting The Form On Top */
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2
Public Const SWP_SHOWWINDOW = &H40
Public Const HWND_NOTOPMOST = -2
Public Const HWND_TOPMOST = -1

' /* Declare Variable To Point To Our LogFile */
Global LogFile As String
Global SCount As Integer

Sub SetAlwaysOnTopMode(hWndOrForm As Variant, Optional ByVal OnTop As Boolean = True)
' /* Declare The Variable That Holds The Window Handle Of Our Window */
Dim hWnd As Long

' /* If The Variable Typed Passed To hWndOrForm is a long (window handle) */
If VarType(hWndOrForm) = vbLong Then
    ' /* Set hWnd To The Value Of The Passed Long */
    hWnd = hWndOrForm
Else
    ' /* Otherwise, It's A Form That Has been passed... Grab It's Handle */
    hWnd = hWndOrForm.hWnd
End If

' /* Make The Window Be On Top Of The Others */
SetWindowPos hWnd, IIf(OnTop, HWND_TOPMOST, HWND_NOTOPMOST), 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW
End Sub

